package com.easyto.controller;

import com.easyto.response.UserDTO;
import com.google.common.collect.Lists;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.concurrent.TimeUnit;

@RestController
@RequestMapping("/feign")
public class PayController {


    @GetMapping("/getApi")
    public String getApi() {

        System.out.println(">>>>>>>>>>>>>>>> PayController  start " + System.currentTimeMillis());
        try {
            TimeUnit.SECONDS.sleep(60);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(">>>>>>>>>>>>>>>> PayController  end " + System.currentTimeMillis());

        return "easyto-pay feign";
    }


    @GetMapping("/getUser/{uuId}")
    public UserDTO getUser(@PathVariable("uuId") String userId) {

//        int a = 1 / 0; // 降级测试
        System.out.println(">>>>>>>>>>>>>>>> PayController getUser start " + System.currentTimeMillis());
        try {
            TimeUnit.SECONDS.sleep(30);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(">>>>>>>>>>>>>>>> PayController getUser end " + System.currentTimeMillis());

        List<UserDTO> list = Lists.newArrayList();

        for (int i = 0; i < 10; i++) {

            list.add(new UserDTO(i + "", "name_" + i, i + ""));

        }

        UserDTO userDTO = list.stream().filter(e -> userId.equals(e.getId())).findFirst()
                .orElse(null);


        System.out.println(">>>>>>>>>>>>>>> " + userId);
        return userDTO;
    }
}
